package com.scoy.honeymei.activity.mall;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;

import com.google.gson.Gson;
import com.lzy.okgo.model.HttpParams;
import com.scoy.honeymei.R;
import com.scoy.honeymei.base.BaseActivity;
import com.scoy.honeymei.bean.TripOrderBean;
import com.scoy.honeymei.http.HpCallback;
import com.scoy.honeymei.http.HpGo;
import com.scoy.honeymei.url.MeConstant;
import com.scoy.honeymei.url.MyUrl;
import com.scoy.honeymei.utils.IntentUtil;
import com.scoy.honeymei.utils.MyUtil;
import com.scoy.honeymei.utils.SPHelper;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @ClassName: TravelMeDetailActivity$
 * @Description: 我的订单出行详情
 * @Author: GaoZhan
 * @CreateDate: 2019/9/9/0009$ 下午 14:53$
 * @UpdateUser: 更新者
 * @UpdateDate: 2019/9/9/0009$ 下午 14:53$
 * @UpdateRemark: 更新内容
 */
public class TripMeDetailActivity extends BaseActivity {


    @BindView(R.id.back_iv)
    ImageView backIv;
    @BindView(R.id.title_tv)
    TextView titleTv;
    @BindView(R.id.sign_tv)
    TextView signTv;
    @BindView(R.id.title_llt)
    LinearLayout titleLlt;
    @BindView(R.id.film_name_tv)
    TextView filmNameTv;
    @BindView(R.id.film_time_tv)
    TextView filmTimeTv;
    @BindView(R.id.film_moneysign_tv)
    TextView filmMoneysignTv;
    @BindView(R.id.film_money_tv)
    TextView filmMoneyTv;
    @BindView(R.id.trip_cannum_tv)
    TextView tripCannumTv;
    @BindView(R.id.trip_remainnum_tv)
    TextView tripRemainnumTv;
    @BindView(R.id.item_trip)
    ConstraintLayout itemTrip;
    @BindView(R.id.dtm_tv0)
    TextView dtmTv0;
    @BindView(R.id.dtm_name_tv)
    TextView dtmNameTv;
    @BindView(R.id.dtm_tv1)
    TextView dtmTv1;
    @BindView(R.id.dtm_phone_tv)
    TextView dtmPhoneTv;
    @BindView(R.id.dtm_tv3)
    TextView dtmTv3;
    @BindView(R.id.dtm_buynum_tv)
    TextView dtmBuynumTv;
    @BindView(R.id.dtm_tv5)
    TextView dtmTv5;
    @BindView(R.id.dtm_sigleprice_tv)
    TextView dtmSiglepriceTv;
    @BindView(R.id.dtm_tv6)
    TextView dtmTv6;
    @BindView(R.id.dtm_chargeprice_tv)
    TextView dtmChargepriceTv;
    @BindView(R.id.dtm_tv7)
    TextView dtmTv7;
    @BindView(R.id.dtm_allprice_tv)
    TextView dtmAllpriceTv;
    @BindView(R.id.dtm_cl0)
    ConstraintLayout dtmCl0;
    @BindView(R.id.dtm_tv2)
    TextView dtmTv2;
    @BindView(R.id.dtm_content_tv)
    TextView dtmContentTv;
    @BindView(R.id.dtm_cl1)
    ConstraintLayout dtmCl1;
    @BindView(R.id.dtm_tv8)
    TextView dtmTv8;
    @BindView(R.id.dtm_tv9)
    TextView dtmTv9;
    @BindView(R.id.dtm_ordernum_tv)
    TextView dtmOrdernumTv;
    @BindView(R.id.dtm_tv10)
    TextView dtmTv10;
    @BindView(R.id.dtm_creattime_tv)
    TextView dtmCreattimeTv;
    @BindView(R.id.dtm_tv11)
    TextView dtmTv11;
    @BindView(R.id.dtm_paytime_tv)
    TextView dtmPaytimeTv;
    @BindView(R.id.film_ddphone_tv)
    TextView filmDdphoneTv;
    @BindView(R.id.film_tophone_tv)
    TextView filmTophoneTv;
    private TripMeDetailActivity mContext;
    private int type;
    private int tid;
    private String phone;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tripme_detail);
        ButterKnife.bind(this);
        mContext = TripMeDetailActivity.this;
        type = getIntent().getIntExtra("type", 0);
        tid = getIntent().getIntExtra("tid", 0);

        initNormal();

        httpTripDetail();

        httpDDphone();

    }

    @Override
    public void initNormal() {
        titleTv.setText(R.string.orderdetail);

        MyUtil.setStatusBar(mContext, getWindow(), true, R.color.colorWhite);
        titleLlt.setPadding(0, MyUtil.getStatusBarHeight(mContext), 0, 0);
    }


    @OnClick({R.id.back_iv, R.id.film_tophone_tv})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back_iv:
                finish();
                break;
            case R.id.film_tophone_tv:
                IntentUtil.callPhone1(mContext, phone);
                break;
        }
    }

    private void httpTripDetail() {
        HttpParams params = new HttpParams();
        params.put("uid", SPHelper.getString(MeConstant.UID, ""));
        params.put("order_id", tid);
        HpGo.newInstance().HttpGo(this, MyUrl.TRIP_ORDER_DETAIL, params, new HpCallback() {
            @Override
            public void onSuccess(String o) {
                TripOrderBean tripOrderBean = new Gson().fromJson(o, TripOrderBean.class);

                filmNameTv.setText(tripOrderBean.getStart_place() + "-" + tripOrderBean.getDestination());
                filmMoneyTv.setText(tripOrderBean.getOld_money());
                filmTimeTv.setText("时间：" + tripOrderBean.getStarttime());
                tripCannumTv.setText("车牌号：" + tripOrderBean.getBus_no());
                tripRemainnumTv.setText("购买座位：" + tripOrderBean.getNum() + "位");

                dtmNameTv.setText(tripOrderBean.getName());
                dtmPhoneTv.setText(tripOrderBean.getTel());
                dtmBuynumTv.setText(tripOrderBean.getNum() + "");

                dtmSiglepriceTv.setText("￥" + tripOrderBean.getOld_money());
                dtmChargepriceTv.setText("-￥" + tripOrderBean.getCoupon_money());
                dtmAllpriceTv.setText("￥" + tripOrderBean.getMoney());

                dtmOrdernumTv.setText(tripOrderBean.getOrder_no());
                dtmCreattimeTv.setText(tripOrderBean.getCreatetime());
                dtmPaytimeTv.setText(tripOrderBean.getPaytime());

            }

            @Override
            public void onFailed(String code, String msg, String o) {
                MyUtil.mytoast(mContext, code + "," + msg);
            }

            @Override
            public void onError(int code, String errorMsg) {
                MyUtil.mytoast(mContext, errorMsg);
            }
        });

    }

    private void httpDDphone() {
        HttpParams params = new HttpParams();
        HpGo.newInstance().HttpGo(this, MyUrl.TRIP_PHONE, params, new HpCallback() {
            @Override
            public void onSuccess(String o) {
                phone = o;
                filmDdphoneTv.setText("调度电话：" + o);
            }

            @Override
            public void onFailed(String code, String msg, String o) {
                MyUtil.mytoast(mContext, code + "," + msg);
            }

            @Override
            public void onError(int code, String errorMsg) {
                MyUtil.mytoast(mContext, errorMsg);
            }
        });

    }


}
